﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
public partial class Scores_ScoresAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            StoreCompanyBind(); 
        } 
    }
    protected void RowSelect(object s, AjaxEventArgs e)
    {
        Query q = new Query(CxCompanyBase.Schema);
        q.AddWhere("companyid", e.ExtraParams["companyid"]);
        q.SetSelectList("guid");
        if(q.GetRecordCount()>0)
        {
            IDataReader dr = q.ExecuteReader();
            if(dr.Read())
            {
                tfcompanyid.Value = e.ExtraParams["companyid"];
            }
        }
        
    }
    protected void StoreCompany_OnRefreshData(object s, StoreRefreshDataEventArgs e)
    {
        StoreCompanyBind();
    }
    protected void StoreCompanyBind()
    {
        Query q = new Query(VwCompanybase.Schema);
        q.SetSelectList("companyid,companyname,companyaddress,electricname,tradename,deptname,scores,credit");
        q.AddWhere("depid", Cookies.getCookies("cdeptid"));
        StoreCompany.DataSource = q.ExecuteDataSet();
        StoreCompany.DataBind();
    }

    protected void SubChengxin(object s,AjaxEventArgs e)
    {
        if (tfcompanyid.Value.ToString() == "")
        {
            Err.Warning("请从左侧选择一个客户！", MessageBox.Icon.WARNING);
            return;
        }
            Guid g = Guid.NewGuid();
            string companyid = tfcompanyid.Value.ToString();
            ChengxinInsert(1, NumberField1, g);
            ChengxinInsert(2, NumberField2, g);
            ChengxinInsert(3, NumberField3, g);
            ChengxinInsert(4, NumberField4, g);
            ChengxinInsert(5, NumberField5, g);
            ChengxinInsert(6, NumberField6, g);
            ChengxinInsert(7, NumberField7, g);
            ChengxinInsert(8, NumberField8, g);
            ChengxinInsert(9, NumberField9, g);
            ChengxinInsert(10, NumberField10, g);
            ChengxinInsert(11, NumberField11, g);
            ChengxinInsert(12, NumberField12, g);
            ChengxinInsert(13, NumberField13, g);
            ChengxinInsert(14, NumberField14, g);
            ChengxinInsert(15, NumberField15, g);
            ChengxinInsert(16, NumberField16, g);
            ChengxinInsert(17, NumberField17, g);
            CXFileUpload.Sv(FileUploadField1, g);
            Err.Warning("提交成功!",MessageBox.Icon.NONE);
            tfcompanyid.Clear();

    }
    protected void ChengxinInsert(int id, NumberField nf,Guid g)
    {
        CxChengxin cx = new CxChengxin();
        cx.Guid = g;
        cx.Uid = int.Parse(Cookies.getCookies("cuid"));
        cx.CompanyID = tfcompanyid.Value.ToString();
        cx.ChengXinID = id;
        cx.Scores = int.Parse(nf.Value.ToString());
        cx.Status = 0;
        cx.Save(); 
        
    }
}
